const toast = require('./toast.js')
const checkEmpty = (checkData, errMessage = '校验失败') => {
  if (!checkData) { // "",null,undefined,NaN
    toast.showToast(errMessage)
    return false
  }
  return checkData
}

const checkData = (checkData, checkTile = "", errMessage = '校验失败') => {
  if (!checkData) { // "",null,undefined,NaN
    toast.showToast(checkTile + errMessage)
    return false
  }
  return checkData
}
const checkEmail = (checkData, errMessage = '校验失败') => {
  if (!(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/).test(checkData)) {
    toast.showToast(errMessage)
    return false
  }
  return checkData
}

module.exports = {
  checkEmpty,
  checkData,
  checkEmail
}